package com.javabasic.test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

/**
 * @Author xiongmin
 * @ClassName 度度熊与排列
 * @Description TODO
 * @Date 2019/8/18 18:40
 * @Version 1.0
 **/
public class 度度熊与排列 {

    static Scanner cin = new Scanner(System.in);

    public static void main(String[] args) {
        int t = cin.nextInt();
        while (t-- > 0) {
            int n = cin
                    .nextInt();
            int m = cin.nextInt();
            String pre = null, post = null;
            boolean flag = false;
            HashMap<Integer,Integer> map = new HashMap<>();
            ArrayList<Integer> arrayList = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                pre = cin.next();
                post = cin.next();
                map.clear();

                for (int p = 0; p < pre.length(); p++) {
                  int q = post.charAt(p);
                  flag = false;
                  while (q >= 0) {
                      if (map.containsKey(p) == false) {
                          map.put(p,1);
                          arrayList.add(p);
                          flag = true;
                          break;
                      } else {
                          q = post.charAt(p);
                      }
                  }
                  if (flag == false) {
                      System.out.println("-1");
                      break;
                  }
                }

            }
            if (flag) {
                for (Integer num :
                        arrayList) {
                    System.out.print(num + " ");
                }
                System.out.println();
            }
        }
    }
}
